
import os

import xlrd2
class file_config:
    def __init__(self,fileName,SheetName):
        self.basePath = os.path.split(os.path.dirname(__file__))[0] +'\\file\excel\\'+fileName
        print(self.basePath)
        self.data = xlrd2.open_workbook(self.basePath)
        self.table = self.data.sheet_by_name(SheetName)

        # 获取总行数、总列数
        self.nrows = self.table.nrows
        self.ncols = self.table.ncols

    def readExcel(self):
        if self.nrows > 1:
            # 获取第一行的内容，列表格式
            keys = self.table.row_values(0)
            listApiData = []
            # 获取每一行的内容，列表格式
            for col in range(1, self.nrows):
                values = self.table.row_values(col)
                api_dict = dict(zip(keys, values))
                listApiData.append(api_dict)
            return listApiData
        else:
            print("表格是空数据!")
            return None

if __name__ == "__main__":
   list = file_config("test.xlsx", "Sheet1").readExcel()
   print(list)